package com.ruoyi.mall.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.mall.api.RemoteMallService;
import com.ruoyi.mall.api.domian.Product;
import com.ruoyi.mall.api.domian.RecommendProductsVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

public class RemoteMallFallbackFactory   implements FallbackFactory<RemoteMallService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteMallFallbackFactory.class);

    @Override
    public RemoteMallService create(Throwable cause) {
        log.error("mall服务调用失败:{}", cause.getMessage());
        return new RemoteMallService(){

            @Override
            public R<List<Product>> getRecommendProducts(RecommendProductsVO<?> vo, String source) {
                return R.fail("根据诊断结果获取推荐商品失败:" + cause.getMessage());
            }
        };
    }
}
